﻿//-----------------------------------------------------------------------
// <copyright file="Helpers.cs" company="deixei.com">
//     Copyright (c) deixei.com. All rights reserved.
// </copyright>
// <author>Marcio Parente</author>
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Routing;
using Deixei;


namespace Deixei.Web
{
    /// <summary>
    /// Web Helpers
    /// </summary>
    public static class Helpers
    {
        /// <summary>
        /// Deixeis the web context.
        /// </summary>
        /// <param name="viewContext">The view context.</param>
        /// <returns></returns>
        public static DeixeiWebContext DeixeiWebContext(this ViewContext viewContext)
        {
            return viewContext.RequestContext.DeixeiWebContext();
        }

        /// <summary>
        /// Deixeis the web context.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <returns></returns>
        public static DeixeiWebContext DeixeiWebContext(this RequestContext requestContext)
        {
            DeixeiWebContext context = requestContext.HttpContext.Items["DeixeiWebContext"] as DeixeiWebContext;
            if (context == null)
            {
                context = new DeixeiWebContext(requestContext);
                requestContext.HttpContext.Items["DeixeiWebContext"] = context;
            }
            return context;
        }

    }
}
